version: '3.8'
services:
  db:
    container_name: project_data_base
    image: postgres:latest
    restart: always
    env_file: ./.env
    healthcheck:
      test: ["CMD-SHELL", "pg_isready -U postgres"]
      interval: 5s
      timeout: 5s
      retries: 5
    environment:
      - POSTGRES_USER=$POSTGRESDB_USER
      - POSTGRES_PASSWORD=$POSTGRESDB_ROOT_PASSWORD
      - POSTGRES_DB=$POSTGRESDB_DATABASE
    ports:
      - $POSTGRESDB_LOCAL_PORT:$POSTGRESDB_DOCKER_PORT
    volumes:
      - project_volume:/var/lib/postgresql/data/
      - ./db/init.sql:/docker-entrypoint-initdb.d/create_tables.sql
  app:
    depends_on:
      - db
    build: ./deephack-agents-app
    container_name: app_api
    restart: unless-stopped
    env_file: ./.env
    ports:
      - $NODE_LOCAL_PORT:$NODE_DOCKER_PORT
    environment:
      - DB_HOST=db
      - DB_USER=$POSTGRESDB_USER
      - DB_PASSWORD=$POSTGRESDB_ROOT_PASSWORD
      - DB_NAME=$POSTGRESDB_DATABASE
      - DB_PORT=$POSTGRESDB_DOCKER_PORT
    stdin_open: true
    tty: true
  client:
    build: ./deephack-agents-client
    container_name: client_frontend
    ports:
      - $CLIENT_LOCAL_PORT:$CLIENT_DOCKER_PORT
    volumes:
      - ./client:/deephack-agents-client
      - /deephack-agents-client/node_modules
    stdin_open: true
    tty: true
  nginx:
    ports:
      - "${HTTP_PORT}:80"
    build:
      context: ./containers/nginx
      dockerfile: ./Dockerfile
      args:
        USER_ID: "$USER_ID"
        GROUP_ID: "$GROUP_ID"
        PROJECT_PREFIX: ${PROJECT_PREFIX}
    container_name: ${PROJECT_PREFIX}_webserver
    depends_on:
      - mysql
    volumes:
      - ./api:/home/giga/api
      - ./logs/nginx:/var/log/nginx
    links:
      - php
    restart: unless-stopped
    environment:
      - APP_ENV=${APP_ENV}
      - PROJECT_PREFIX=${PROJECT_PREFIX}
    networks:
      default:
        aliases:
          - ${PROJECT_PREFIX}.localhost
  php:
    build:
      context: ./containers/php
      dockerfile: ./Dockerfile
      args:
        USER_ID: "$USER_ID"
        GROUP_ID: "$GROUP_ID"
    container_name: ${PROJECT_PREFIX}_php
    volumes:
      - ./api:/home/giga/api
      - ./logs/php:/var/log/php
    links:
      - mysql
    restart: unless-stopped
    environment:
      APP_ENV: ${APP_ENV}
      MYSQL_DATABASE: ${MYSQL_DATABASE}
      MYSQL_USER: ${MYSQL_USER}
      MYSQL_PASSWORD: ${MYSQL_PASSWORD}
      MYSQL_HOST: ${MYSQL_HOST}
      PROJECT_PREFIX: ${PROJECT_PREFIX}
      PHP_IDE_CONFIG: serverName=serverName
    extra_hosts:
      - "host.docker.internal:host-gateway"
  composer:
    image: composer
    network_mode: bridge
    volumes:
      - ./api:/home/giga/api
    working_dir: /home/giga/api
    entrypoint:
      - composer
      - update
    depends_on:
      - php
  mysql:
    platform: "linux/x86_64"
    ports:
      - "33060:3306"
    build:
      context: ./containers/mysql
      dockerfile: ./Dockerfile
      args:
        USER_ID: "$USER_ID"
        GROUP_ID: "$GROUP_ID"
    container_name: ${PROJECT_PREFIX}_mysql
    environment:
      MYSQL_DATABASE: ${MYSQL_DATABASE}
      MYSQL_USER: ${MYSQL_USER}
      MYSQL_PASSWORD: ${MYSQL_PASSWORD}
      MYSQL_ROOT_PASSWORD: password
    volumes:
      - ./logs/mysql:/var/log/mysql
      - ./data/mysql:/var/lib/mysql
    restart: unless-stopped
#  phpmyadmin:
#    build:
#      context: ./containers/phpmyadmin
#      dockerfile: ./Dockerfile
#    ports:
#      - "8080:80"
#    environment:
#      MYSQL_DATABASE: ${MYSQL_DATABASE}
#      MYSQL_USER: ${MYSQL_USER}
#      MYSQL_PASSWORD: ${MYSQL_PASSWORD}
#      MYSQL_ROOT_PASSWORD: password
#    depends_on:
#      - mysql
  flask_web:
    container_name: flask_web_container
    build:
      context: ./containers/python
      dockerfile: ./Dockerfile
    ports:
      - '8123:5000'
    volumes:
      - ./giga:/giga
    restart: unless-stopped
volumes:
  project_volume:
    name: my_project_volume